<template>
    <div>

        <div v-show="ad==1">
            <el-menu>
                <el-menu-item><a @click="GetExpType"  >+ 添加</a></el-menu-item>
            </el-menu>

            <el-table :data="hrdegrees" height="200" border style="width: 100%">
                <el-table-column label="编号" prop="id"></el-table-column>
                <el-table-column label="起止时间" prop="degreeStartdate"></el-table-column>
                <el-table-column label="结束时间" prop="degreeEnddate"></el-table-column>
                <el-table-column label="毕业学校" prop="degreeSchool"></el-table-column>
                <el-table-column label="主修专业 " prop="degreeMajor"></el-table-column>
                <el-table-column label="获得学历" prop="degreeEducation"></el-table-column>
                <el-table-column label="获得学位" prop="degreeDegrees"></el-table-column>
                <el-table-column label="证书编号" prop="degreeCrednum"></el-table-column>
                <el-table-column label="全日制">
                    <template scope="scope">
                        <p v-if="scope.row.degreeFulltime=='Y'">是</p >
                        <p v-if="scope.row.degreeFulltime=='N'">否</p >
                    </template>
                </el-table-column>
                <el-table-column label="所在地" prop="degreeSite"></el-table-column>
                <el-table-column label="操作">
                    <template slot-scope="scope">
                        <el-dropdown>
                            <el-button type="primary" size="small">
                                操作<i class="el-icon-arrow-down el-icon--right"></i>
                            </el-button>
                            <el-dropdown-menu slot="dropdown">
                                <el-dropdown-item size="small" @click.native="UpExpType(scope)">修改</el-dropdown-item>
                                <el-dropdown-item size="small" @click.native="del(scope)">删除</el-dropdown-item>
                            </el-dropdown-menu>
                        </el-dropdown>
                    </template>
                </el-table-column>
            </el-table>
        </div>
        <div v-if="ad==2">
            <el-form :model="hrdegree" :rules="rules" ref="recordForm" class="demo-ruleForm">
                <el-row>
                    <el-col :span="10">
                        <el-form-item label="起止时间：" prop="degreeStartdate">
                            <el-input v-model="hrdegree.degreeStartdate" type="date" size="small" placeholder="起止时间"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="10">
                        <el-form-item label="结束时间：" prop="degreeEnddate">
                            <el-input v-model="hrdegree.degreeEnddate" type="date" size="small" placeholder="结束时间"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="10">
                        <el-form-item label="毕业院校：" prop="degreeSchool">
                            <el-input v-model="hrdegree.degreeSchool" size="small" placeholder="毕业院校"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="10">
                        <el-form-item label="主修专业：" prop="degreeMajor">
                            <el-input v-model="hrdegree.degreeMajor" size="small" placeholder="主修专业"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="10">
                        <el-form-item label="获得学历：" prop="degreeEducation">
                            <el-input v-model="hrdegree.degreeEducation" size="small" placeholder="获得学历"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="10">
                        <el-form-item label="学位：" >
                            <el-input v-model="hrdegree.degreeDegrees" size="small" placeholder="学位"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="10">
                        <el-form-item label="证书编号：">
                            <el-input v-model="hrdegree.degreeCrednum"  size="small" placeholder="证书编号"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="10">
                        <el-form-item label="是否全日制：">
                            <el-radio-group v-model="hrdegree.degreeFulltime">
                                <el-radio label="Y">是</el-radio>
                                <el-radio label="N">否</el-radio>
                            </el-radio-group>
                        </el-form-item>
                      </el-col>
                </el-row>
                <el-row>

                    <el-col :span="10">
                        <el-form-item label="所在地：">
                            <el-input v-model="hrdegree.degreeSite"  size="small" placeholder="快件名"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>

                <el-form-item >
                    <el-button type="primary" @click="addexptype('recordForm')" :disabled="disable" size="small" >提交</el-button>
                    <el-button type="primary" @click="coles" size="small" >取消</el-button>
                </el-form-item>
            </el-form>
        </div>
    </div>
</template>

<script>
    import hrderee from "../../../model/gsl/HrDeree/hrderee";
    const hrd=hrderee.getInstance();
    export default {
        props:["eorkId"],
        name: "ExpressType",
        data(){
            var degreeStartdate = (rule, value, callback) => {
                value=this.hrdegree.degreeStartdate;
                if (!value) {
                    this.disable=true;
                    callback(new Error('请选择起止日期'));
                } else {
                    callback();
                    this.disable=false;
                }
            }; var degreeEnddate = (rule, value, callback) => {
                value=this.hrdegree.degreeEnddate;
                if (!value) {
                    this.disable=true;
                    callback(new Error('请选择结束日期'));
                } else {
                    callback();
                    this.disable=false;
                }
            }; var degreeSchool = (rule, value, callback) => {
                value=this.hrdegree.degreeSchool;
                if (!value) {
                    this.disable=true;
                    callback(new Error('请输入毕业院校'));
                } else {
                    callback();
                    this.disable=false;
                }
            }; var degreeMajor = (rule, value, callback) => {
                value=this.hrdegree.degreeMajor;
                if (!value) {
                    this.disable=true;
                    callback(new Error('请输入主修专业'));
                } else {
                    callback();
                    this.disable=false;
                }
            }; var degreeEducation = (rule, value, callback) => {
                value=this.hrdegree.degreeEducation;
                if (!value) {
                    this.disable=true;
                    callback(new Error('请输入学历'));
                } else {
                    callback();
                    this.disable=false;
                }
            };var degreeFulltime = (rule, value, callback) => {
                value=this.hrdegree.degreeFulltime;
                if (!value) {
                    this.disable=true;
                    callback(new Error('选择是否全日制'));
                } else {
                    callback();
                    this.disable=false;
                }
            };
            return{
                hrdegrees:[],
                hrdegree:{},
                empId: JSON.parse(JSON.stringify(this.eorkId)),//父类传来的id
                ad:1,
                disable:true,
                rules: {
                    degreeStartdate: [{ required: true,validator: degreeStartdate, trigger: 'blur' }],
                    degreeEnddate: [{ required: true,validator: degreeEnddate, trigger: 'blur' }],
                    degreeSchool: [{ required: true,validator: degreeSchool, trigger: 'blur' }],
                    degreeMajor: [{ required: true,validator: degreeMajor, trigger: 'blur' }],
                    degreeEducation: [{ required: true,validator: degreeEducation, trigger: 'blur' }],
                    degreeFulltime: [{ required: true,validator: degreeFulltime, trigger: 'blur' }],
                }
            }
        },
        created(){
            this.getall();
        },
        methods: {
            getall(){
                hrd.listByempId(this.empId).then((re)=>{
                    this.hrdegrees=re.data.data;
                })
            },
            del(so){
                hrd.remove(so.row.id).then((re)=>{
                    if (re.data.data==1) {
                        this.$message.success({
                            message:'删除成功',
                            duration:1000
                        })
                        this.getall();
                    }else {
                        alert("删除失败！")
                        this.getall();
                    }
                })
            },
            GetExpType(){
                this.hrdegree={};
                this.ad=2;
            },
            UpExpType(ss){
                this.ad=2;
                hrd.listByid(ss.row.id).then((re)=>{
                    this.hrdegree={};
                    this.hrdegree=re.data.data;
                })
            },
            coles(){
                this.ad=1;
            },
            addexptype(formName){
                this.$refs[formName].validate((valid) => {
                    if (valid) {
                        this.hrdegree.hrEmpId=this.empId;
                        if (this.hrdegree.id) {
                            hrd.update(this.hrdegree).then((re)=>{
                                if (re.data.data==1) {
                                    this.$message.success({
                                        message:'修改成功',
                                        duration:1000
                                    })
                                    this.getall();
                                    this.hrdegree={}
                                    this.ad=1;
                                }else {
                                    alert("修改失败！")
                                    this.ad=2;
                                }
                            })
                        }else {
                            hrd.save(this.hrdegree).then((re)=>{
                                if (re.data.data==1) {
                                    this.$message.success({
                                        message:'添加成功',
                                        duration:1000
                                    })
                                    this.hrdegree={}
                                    this.getall();
                                    this.ad=1;
                                }else {
                                    alert("添加失败！")
                                    this.ad=2;
                                }
                            })
                        }
                        this.hrdegree={};
                    } else {
                        console.log('error submit!!');
                        return false;
                    }
                });

            }
        }
    }
</script>

<style scoped>

</style>